<style>
.layui-form-pane .layui-form-label{width:auto;}
.layui-form-item{margin-bottom: 0px;}
</style>
<form class="layui-form layui-form-pane" action="{:url()}" method="get" id="hisi-table-search">
<div class="layui-form-item">
 
 <div class="layui-inline">
 	<label class="layui-form-label">物料名称</label>
     <div class="layui-input-inline">
         <input type="text" name="name" lay-verify="" placeholder="输入物料名称" class="layui-input">
     </div>
 </div>
 <div class="layui-inline">
 	<label class="layui-form-label">物料SKU</label>
     <div class="layui-input-inline">
         <input type="text" name="material_sku" lay-verify="" placeholder="输入物料SKU" class="layui-input">
     </div>
 </div>
 <div class="layui-inline">
 	<label class="layui-form-label">颜色</label>
     <div class="layui-input-inline">
         <input type="text" name="color" lay-verify="" placeholder="输入物料颜色" class="layui-input">
     </div>
 </div>
 <div class="layui-inline">
 	<button type="submit" class="layui-btn" lay-submit="" lay-filter="demo1">搜索</button>
 </div>
</div>
</form>


<table id="dataTable"></table>

{include file="system@block/layui" /}

<script type="text/html" title="操作按钮模板" id="buttonTpl">
	<a href="javascript:void(0)" class="layui-btn layui-btn-xs select-item" data-json='{{ JSON.stringify(d) }}' title="选择">选择</a>
</script>
<script type="text/html" id="useTimeTpl">
    <div>{{layui.util.toDateString(d.use_time * 1000) }}</div>
</script>

<script type="text/javascript">
    layui.use(['jquery', 'table', 'tool', 'layer'], function() {
    	var $ = layui.jquery;
        var table = layui.table;
        var layer = layui.layer;
        table.render({
            elem: '#dataTable'
            ,url: '{:url()}' //数据接口
            ,page: true //开启分页
            ,skin: 'row'
            ,even: true
            ,limit: 20
            ,limits: [20,50,100,150,200]
            ,text: {
                none : '暂无相关数据'
            }
            ,toolbar: false
            ,cols: [[ //表头
                {field: 'id', title: '编号',width: 80}
                ,{field: 'name', title: '物料名称',width: 100}
                ,{field: 'material_sku', title: '物料SKU',width: 100}
                ,{field: 'type', title: '类型',width: 80, templet:function(d){return layui.tool.formatMaterialType(d.type)}}
                ,{field: 'supplier', title: '供应商',width: 100}
                ,{field: 'model', title: '型号',width: 100}
                ,{field: 'colornum', title: '色号',width: 80}
                ,{field: 'color', title: '颜色',width: 80}
                ,{field: 'purchasing_unit', title: '单位',width: 60}
                ,{field: 'price', title: '单价',width: 80}
                ,{field: '', title: '最近使用时间', templet: '#useTimeTpl',width: 150}
                ,{field: '', title: '操作', templet: '#buttonTpl', fixed: 'right',width: 100}
            ]]
        });
        
        $(document).on('click', '.select-item',function(){
        	var d = JSON.parse($(this).attr('data-json'));
        	var html = '<tr>';
        	html += '<td>'+d.name+'</td>';
        	html += '<td>'+d.material_sku+'</td>';
        	html += '<td>'+d.model+'</td>';
        	html += '<td>'+d.colornum+'</td>';
        	html += '<td>'+d.color+'</td>';
        	html += '<td><input type="text" name="customer_dosage['+d.id+']" value="0" autocomplete="off" class="layui-input" lay-verify="required|number"></td>';
        	html += '<td><input type="text" name="material_dosage['+d.id+']" value="0" autocomplete="off" class="layui-input" lay-verify="required|number"></td>';
        	html += '<td><input type="text" name="accurate_dosage['+d.id+']" value="0" autocomplete="off" class="layui-input" lay-verify="number"></td>';
        	html += '<td><input type="text" name="tube_weight['+d.id+']" value="0" autocomplete="off" class="layui-input" lay-verify="number"></td>';
        	html += '<td><input type="text" name="diff_meters['+d.id+']" value="0" autocomplete="off" class="layui-input" lay-verify="number"></td>';
        	html += '<td>'+d.customer_price+'</td>';
        	html += '<td>'+d.price+'</td>';
        	html += '<td>'+d.fabric_width+'</td>';
        	html += '<td><a href="javascript:void(0)" class="layui-btn layui-btn-danger layui-btn-sm btn-del"><i class="layui-icon">&#xe640;</i></a></td>';
        	html += '</tr>';
        	parent.$('.material-list table tbody').append(html);
        	var index = parent.layer.getFrameIndex(window.name);
        	parent.layer.close(index);
		});
    });
</script>